package vn.mhg.user;

import java.util.HashMap;

public class UserManager {
	static UserManager instance = new UserManager();
	private static long lastSessionId = System.currentTimeMillis();
	private final HashMap<String, User> userMap = new HashMap<String, User>();
	
	public void endUserSession(String sessionId) {
		User user = this.userMap.remove(sessionId);
		if (user == null) {
			System.out.println("Can't find user's session to remove. Memory leak may occur.");
		} else {
			System.out.println("End user session:" + sessionId + " Total :" + userMap.size());
		}
	}
	
	public User createUser() {
		User user = new User(String.valueOf(lastSessionId++));
		userMap.put(user.sessionId, user);
		System.out.println("new user sessionid:" + user.sessionId + "(tota :"+userMap.size());
		return user;
	}
	public static UserManager getInstance() {
		return instance;
	}
	public User getUser(String sessionId) {
		return userMap.get(sessionId);
	}
}
